<?php

class Application_Model_Pekerja extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_pekerja';
    
    public function pekerjaBaru($data)
    {
        $this->insert($data);
    }
    
    public function pekerjaDelete($id, $id_project)
    {
        $this->delete('id_pegawai = '.$id.' and id_proyek = '.$id_project.' and tanggung_jawab = "Staff"');
    }
    
    public function gantiManager($data, $id_proyek)
    {
        $this->update($data, 'id_proyek = '.$id_proyek.' and tanggung_jawab = "Manajer Proyek"');
    }
    
    public function getProject($id_project)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->where('id_proyek = '.$id_project.' and tanggung_jawab = "Staff"');
        
        $result = $this->fetchAll($select);
        
        if($result->toArray() != null) {
            return true;
        }
        else
            return false;
    }

    public function getData($id)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->where('id_proyek = ?',$id)
               ->where('tanggung_jawab = ?','Staff')
               ->joinLeft('tabel_pegawai', 'tabel_pegawai.id_pegawai = tabel_pekerja.id_pegawai');
               
        $result = $this->fetchAll($select);
        
        if($result)
            return $result->toArray();
        else
            return false;
    }
    
    public function getDataManager($id)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->where('id_proyek = ?',$id)
               ->where('tanggung_jawab = ?', 'Manajer Proyek')
               ->joinLeft('tabel_pegawai', 'tabel_pegawai.id_pegawai = tabel_pekerja.id_pegawai');
               
        $result = $this->fetchAll($select);
        
        if($result)
            return $result->toArray();
        else
            return false;
    }
    
    public function checkPekerja($id)
    {
        $select = $this->select();
        $select->setIntegrityCheck(false)
               ->from($this->_name)
               ->where('id_pegawai = ?',$id);
       $result = $this->fetchRow($select);
        if($result)
            return false;
        else
            return true;
    }

}

